<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Marocannonces_model extends CI_Model {

    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function get_annonces() {
        $annonces = array();
        $annonce = new stdClass;
        $html = file_get_html(URL_CIBLE . CAT_AUTOMOTO);
        $i = 0;
        foreach ($html->find('table.listing_table,table.listing_table_last') as $item) {
            //Ajouter base url du site cible dans les hrefs des annonces pour une rediréction simple
            //$annonce->find('a', 0)->setAttribute('href', URL_CIBLE . $annonce->find('a', 0)->getAttribute('href'));
            //$annonce->find('img', 0)->setAttribute('src', URL_CIBLE . $annonce->find('img', 0)->getAttribute('src'));

            $matches = array();
            preg_match('([0-9]+)', $item->find('li.numRefAnn', 0)->plaintext, $matches);
            $this->id_annonce = (int) $matches[0];
            $this->cat_annonce = 'automoto';
            $this->lien_annonce = $item->find('a', 0)->getAttribute('href');
            $this->contenu_annonce = $item->outertext;

            $this->insert_annonce($annonce);
        }

        return $annonces;
    }

    public function insert_annonce() {

        $this->db->insert('marocannonces', $this);
    }

    public function get_all_link_pagination(){
        
        $html = file_get_html(URL_CIBLE . CAT_AUTOMOTO);
        foreach ($html->find('ul.pagination') as $item) {
    }
    
}

/* End of file welcome.php */
/* Location: ./application/models/marocannonces_model.php */